package org.germinus.telcoblocks.infraestructuras.diagram.edit.parts;

import org.eclipse.draw2d.Connection;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITreeBranchEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.swt.graphics.Color;
import org.germinus.telcoblocks.infraestructuras.diagram.edit.policies.EnlaceItemSemanticEditPolicy;

/**
 * @generated
 */
public class EnlaceEditPart extends ConnectionNodeEditPart implements
		ITreeBranchEditPart {

	/**
	 * @generated
	 */
	public static final int VISUAL_ID = 4001;

	/**
	 * @generated
	 */
	public EnlaceEditPart(View view) {
		super(view);
	}

	/**
	 * @generated
	 */
	protected void createDefaultEditPolicies() {
		super.createDefaultEditPolicies();
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
				new EnlaceItemSemanticEditPolicy());
	}

	/**
	 * @generated
	 */
	protected boolean addFixedChild(EditPart childEditPart) {
		if (childEditPart instanceof EnlaceComentarioEditPart) {
			((EnlaceComentarioEditPart) childEditPart)
					.setLabel(getPrimaryShape()
							.getFigureEnlaceComentarioFigure());
			return true;
		}
		return false;
	}

	/**
	 * @generated
	 */
	protected void addChildVisual(EditPart childEditPart, int index) {
		if (addFixedChild(childEditPart)) {
			return;
		}
		super.addChildVisual(childEditPart, -1);
	}

	/**
	 * Creates figure for this edit part.
	 * 
	 * Body of this method does not depend on settings in generation model
	 * so you may safely remove <i>generated</i> tag and modify it.
	 * 
	 * @generated
	 */

	protected Connection createConnectionFigure() {
		return new EnlaceFigure();
	}

	/**
	 * @generated
	 */
	public EnlaceFigure getPrimaryShape() {
		return (EnlaceFigure) getFigure();
	}

	/**
	 * @generated
	 */
	public class EnlaceFigure extends PolylineConnectionEx {

		/**
		 * @generated
		 */
		private WrappingLabel fFigureEnlaceComentarioFigure;

		/**
		 * @generated
		 */
		public EnlaceFigure() {
			this.setLineWidth(2);
			this.setForegroundColor(THIS_FORE);
			this.setBackgroundColor(THIS_BACK);

			createContents();
		}

		/**
		 * @generated
		 */
		private void createContents() {

			fFigureEnlaceComentarioFigure = new WrappingLabel();
			fFigureEnlaceComentarioFigure.setText("<...>");

			this.add(fFigureEnlaceComentarioFigure);

		}

		/**
		 * @generated
		 */
		public WrappingLabel getFigureEnlaceComentarioFigure() {
			return fFigureEnlaceComentarioFigure;
		}

	}

	/**
	 * @generated
	 */
	static final Color THIS_FORE = new Color(null, 212, 215, 2);

	/**
	 * @generated
	 */
	static final Color THIS_BACK = new Color(null, 212, 215, 2);

}
